#include"head.h"

int rmServe(int net_fd,MYSQL *connection){

    char token[256] = {0};

    int token_len = 0;
    recv(net_fd, &token_len, sizeof(int), 0);
    recv(net_fd, token, token_len, 0);
    
    if(strcmp(token, "error") == 0){

        return -1;
    }

    char* user_name = decode_token(token);


    char* argv[3] = {0};

    char protocol[100] = {0};

    recv(net_fd, protocol, sizeof(protocol), 0);


    getToken(protocol, argv);

    char path[100] = {0};



    strcat(path, argv[1]);
    strcat(path, "/");
    strcat(path, argv[2]);


    
    bool stat = false;

    stat = utils_remove_file(connection, user_name, path);

    free(user_name);
    
    if(!stat){
        int s = 0;
        send(net_fd, &s, sizeof(int), MSG_NOSIGNAL);
        return -1;
    }
    
    if(stat){
        int s = 1;
        send(net_fd, &s, sizeof(int), MSG_NOSIGNAL);
    }

    return 0;
}



